<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0,
		minimum-scale=1.0, maximum-scale=1.0"/>
    <meta charset="UTF-8">
    <title>新增发票</title>
    <link href="../public/css/style.css" rel="stylesheet">
    <link href="../public/css/common.css" rel="stylesheet">
    <script src="../public/js/jquery.js"></script>
    <script type="text/javascript" src="../public/js/product.js" ></script>
</head>
<body class="layout_body">
<div class="layout_content graybg">
    <header class="demo-header" style="padding-top: 10px;">
        <div class="titleLeft flt">
            <a href="index.html">
                <img src="../public/img/back.png" width="35px" height="33px">
            </a>
        </div>
        <div class="titleRight flt text-center">新增发票</div>
    </header>
    <div class="whitebg" id="addinvoice">
        <div class="message-detail paddingnot">
            <p class="border1">
                发票金额
                <input class="input" id="invoice_price" type="text" placeholder="请输入发票金额" maxlength="30" required>
            </p>
            <p class="border1 disn rise" id="">
                发票抬头
                <input class="input" id="invoice_rise" type="text" placeholder="请填写您营业执照上的全程" maxlength="30" required>
            </p>

            <p class="border1 pay-select invoiceradio padding-adjust5" id="kaijutype">
                开具类型：
                <input type="radio" class="receipt_type_one" name="receipt_type" value="1" checked="checked"/>
                    <label id="persion" class="pay-check"></label>个人&nbsp;&nbsp;

                <input type="radio" class="receipt_type_two" name="receipt_type" value="2" />
                    <label id="company"></label>企业
            </p>
            <p class="pay-select invoiceradio padding-adjust2 disn" id="invoicetype">
                发票类型：
                <input type="radio" class="invoice_val_one" name="radio1" value="1" checked="checked" /><label id="normal"></label>增值税普通发票&nbsp;&nbsp;
                <input type="radio" class="invoice_val_two" name="radio1" value="2" /><label id="private"></label>增值税专用发票
            </p>
            <p class="padding-adjust2" id="persion-type">
                发票类型：增值税普通发票
            </p>
        </div>
    </div>
    <div class="whitebg disn private-form">
        <div class="message-detail paddingnot">
            <p class="padding-adjust2">
                信用代码
                <input class="input" id="credit_code" type="text" placeholder="请输入统一社会信用代码" maxlength="30" required>
            </p>
            <p class="border1" id="">
                开户名称
                <input class="input" id="account_name" type="text" placeholder="请输入开户名称" maxlength="30" required>
            </p>
            <p class="border1" id="">
                开户银行
                <input class="input" id="account_bank" type="text" placeholder="请输入开户银行" maxlength="30" required>
            </p>
            <p class="border1" id="">
                银行账号
                <input class="input" id="bank_account" type="text" placeholder="请输入银行账号" maxlength="30" required>
            </p>
            <p class="border1" id="">
                场所地址
                <input class="input" id="address" type="text" placeholder="请输入注册场所地址" maxlength="30" required>
            </p>
            <p class="border1" id="">
                固定电话
                <input class="input" id="telephone" type="text" placeholder="请输入注册固定电话" maxlength="30" required>
            </p>
        </div>
    </div>
    <div class="whitebg" style="position: fixed;bottom: 0;width: 100%;">
        <div class="padding-adjust4 border1">
            <a>
                <div class="button-two Cgray add_Invoice">保存</div>
            </a>
            <div class="button-two Cgray">取消</div>
        </div>
    </div>
    <div id="guige" class="invoiceguige">
        <div class="invoice-fuceng">
            增值税普通发票开始小规模纳税人或者开票资料不齐全的购买人，购买人取得后不可以进行进项税额抵扣。
        </div>
        <div class="invoice-confirm" onclick="CloseDiv()"><strong>确定</strong></div>
    </div>
    <div id="fade" class="black_overlay"></div>

    <div id="account" class="invoiceguige" style="height: 220px;">
        <div class="invoice-fuceng">
            增值税专用发票开给一般纳税人，申请时需提供公司名称、税号、地址电话、开户行名称及账号，一般纳税人批复，购买人取得后可以进行进项税额抵扣。
        </div>
        <div class="invoice-confirm" onclick="CloseAccount()"><strong>确定</strong></div>
    </div>
    <div id="fadeAccount" class="black_overlay"></div>
</div>
</body>
<script>
    $('body').on('click','#persion',function () { //个人
        $(".receipt_type_one").attr("checked","checked");
        $(".receipt_type_two").attr("checked",false);
    });
    $('body').on('click','#company',function () { //企业
        $(".receipt_type_one").attr("checked",false);
        $(".receipt_type_two").attr("checked","checked");
        $('#normal').addClass('pay-check');

        $(".invoice_val_one").attr("checked","checked");
        $(".invoice_val_two").attr("checked",false);
        $('#private').removeClass('pay-check');

        $('.private-form').addClass('disn');
    });
    $('body').on('click','#normal',function () { //普通增值税
        $(".invoice_val_one").attr("checked","checked");
        $(".invoice_val_two").attr("checked",false);
    });
    $('body').on('click','#private',function () { //专业增值税
        $(".invoice_val_one").attr("checked",false);
        $(".invoice_val_two").attr("checked","checked");
    });

    /*
     * 添加发票
     */
    $('body').on('click','.add_Invoice',function () {
        var receipt_val = $("input[name='receipt_type']:checked").val();// 开具类型 个人
        var invoice_val = $("input[name='radio1']:checked").val();// 发票类型
        if (invoice_val == undefined || invoice_val == null){
            invoice_val = 1;
        }
        var invoice_price = $('#invoice_price').val(); //发票金额
        var invoice_rise = $('#invoice_rise').val(); //发票抬头
        var credit_code = $('#credit_code').val(); //信用代码
        var account_name = $('#account_name').val(); //开户名称
        var account_bank = $('#account_bank').val(); //开户银行
        var bank_account = $('#bank_account').val(); //银行账号
        var address = $('#address').val(); //地址
        var telephone = $('#telephone').val(); //固定电话

        if (!invoice_price){
            layer.msg('发票金额不能为空!');return;
        }
        if (receipt_val == 2 && invoice_val== 1){
            if (invoice_rise == undefined || invoice_rise == '' || invoice_rise == null){
                layer.msg('发票抬头不能为空!');return;
            }
        }
        if (invoice_val == 2 && receipt_val==2){
            if (invoice_rise == undefined || invoice_rise == '' || invoice_rise == null){
                layer.msg('发票抬头不能为空!');return;
            }
            if (credit_code == undefined || credit_code == '' || credit_code == null){
                layer.msg('信用代码不能为空!');return;
            }
            if (account_name == undefined || account_name == '' || account_name == null){
                layer.msg('开户名称不能为空!');return;
            }
            if (account_bank == undefined || account_bank == '' || account_bank == null){
                layer.msg('开户银行不能为空!');return;
            }
            if (bank_account == undefined || bank_account == '' || bank_account == null){
                layer.msg('银行账号不能为空!');return;
            }
            if (address == undefined || address == '' || address == null){
                layer.msg('场所地址不能为空!');return;
            }
            if (telephone == undefined || telephone == '' || telephone == null){
                layer.msg('固定电话不能为空!');return;
            }
        }
        $.ajax({
            url: '/ajax/Invoice/',
            type: 'post',
            dataType: 'json',
            data:{
                'ajaxdata':'add',
                'receipt_val':receipt_val,
                'invoice_val':invoice_val,
                'invoice_price':invoice_price,
                'invoice_rise':invoice_rise,
                'credit_code':credit_code,
                'account_name':account_name,
                'account_bank':account_bank,
                'bank_account':bank_account,
                'address':address,
                'telephone':telephone,
            },
            success: function (response) {
                layer.msg(response.msg);
                window.location = "/invoice/index";
            },
            beforeSend: function () {
            }
        });
    });

</script>
</html>
